package fr.kirin.logger.model.gui;

import java.net.URL;
import java.util.HashMap;

import javax.swing.Icon;
import javax.swing.ImageIcon;


/**
 * 
 *an icon factory. 
 * @author kirin
 *
 */
public class IconFactory {

	private static final HashMap<String, Icon> iconMap = new HashMap<String, Icon>();

	static{
	    iconMap.put("default", loadIcon("/resources/whiteb.gif"));
		iconMap.put("error", loadIcon("/resources/redb.gif"));
		iconMap.put("info", loadIcon("/resources/greenb.gif"));
		iconMap.put("warning", loadIcon("/resources/orangeb.gif"));
	}

	/**
	 * load an icon with its URL.
	 * It can be package resource like : /resources/icon.png
	 * or external resources /home/user/icon.png.
	 * @param url
	 * @return the loaded icon.
	 */
	public static Icon loadIcon(String url){
		if(!iconMap.containsKey(url)){
			URL resource = IconFactory.class.getResource(url);
			if(resource == null)
				return iconMap.get("default");
			ImageIcon icon = new ImageIcon(resource);
			iconMap.put(url,icon);
			return icon;
		}
		return iconMap.get(url);
	}

	
	public static Icon getDefaultIcon(){
	    return iconMap.get("default");
	}
	public static Icon getErrorIcon(){
		return iconMap.get("error");
	}

	public static Icon getInfoIcon(){
		return iconMap.get("info");
	}
	public static Icon getWarningIcon(){
	    return iconMap.get("warning");
	}







}
